import express from 'express'
import axios from "axios";
import * as cheerio from "cheerio";
import CryptoJS from "./aes.js";

let router = express.Router();
let webHost = "http://www.6uq.cn"
let host = '', protocol = ''
// 获取首页全部数据
router.get("/", async (req, res) => {
    axios
        .post(webHost)
        .then((response) => {
            // console.log(response)
            host = response.request.host
            protocol = response.request.protocol
            // console.log(host, protocol)
            let $ = cheerio.load(response.data);
            let hotSinger = [] // 热门歌手
            $(`div.lksinger_list ul li`).each((index, item) => {
                let a = $(item).find("div.name a")
                let singer = a.text()
                let singerId = a.attr("href").split("/")[2].split(".")[0]

                let img = $(item).find("div.pic a img").attr("src").split('url=')[1]

                hotSinger.push({
                    singer, singerId, img
                })
            })
            let hotVideo = [] // 推荐视频
            $(`div.ilingku_vlist ul li`).each((index, item) => {
                let a = $(item).find("div.pic a")
                let img = a.children("img").attr('src').split('url=')[1]
                let time = a.children("span.pic-hot").text()
                let hot = a.children("span.pic-text").text()

                let b = $(item).find("div.name a")
                let title = b.text()
                let videoId = b.attr("href").split("/")[2].split(".")[0]

                hotVideo.push({
                    img, time, hot, title, videoId
                })
            })
            let lastSong = [] //每日最新单曲推荐
            $(`div.lkmusic_list:eq(1) ul li`).each((index, item) => {
                let a = $(item).find("div.pic a")
                let img = a.children("img").attr('src').split('url=')[1]
                let time = a.children("span").text()

                let b = $(item).find("div.list_r div.name a.url")
                let title = b.text()
                let songId = b.attr("href").split("/")[2].split(".")[0]

                let c = $(item).find("div.list_r p a.singer")
                let singer = c.text()
                let singerId = c.attr("href").split("/")[2].split(".")[0]

                lastSong.push({
                    img, time, title, songId, singer, singerId
                })
            })
            let hotSong = [] // 热门歌单
            $(`div.ilingku_list:eq(0) ul li`).each((index, item) => {
                let a = $(item).find("div.pic")
                let img = a.find("a img").attr('src').split('url=')[1]
                let count = a.children("span").text()

                let b = $(item).find("div.name a")
                let title = b.text()
                let songListId = b.attr("href").split("/")[2].split(".")[0]

                hotSong.push({
                    img, count, title, songListId
                })
            })
            let newSong = [] // 歌曲飙升榜，这里集合网络热歌红歌！
            $("div.play_list ul li").each((index, item) => {
                let a = $(item).find("div.name a")
                let title = a.slice(0, 1).text()
                let songId = a.attr("href").split("/")[2].split(".")[0]
                let singer = a.slice(1, 2).text()
                let singerId = a.attr("href").split("/")[2].split(".")[0]

                let hasVideo = false
                let videoId = ''
                let b = $(item).find("div.mv a")
                if (b.length > 0) {
                    hasVideo = true
                    videoId = b[0].attribs["href"].split("video/")[1].split(".")[0]
                }
                newSong.push({
                    title, songId, singer, singerId, hasVideo, videoId
                })
            })
            return res.json({
                code: 200,
                data: {
                    // hotSearchWord,
                    hotSinger,
                    hotVideo,
                    lastSong,
                    hotSong,
                    newSong
                }
            })
        })
        .catch((error) => {
            console.log(error)
            return res.json({
                code: 201,
                msg: "server error：获取列表失败"
            })
        })
})
// 获取音乐url
router.post("/play", async (req, res) => {
    let {songId} = req.body
    if (!songId)
        return res.json({
            code: 201,
            msg: "缺少必要参数"
        })
    axios.post(`${webHost}/static/js/play.php`, {
        id: songId,
        type: "music"
    }, {
        headers: {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
            "Content-Type": "application/x-www-form-urlencoded",
            "Referer": `${webHost}/static/js/play.php` // 解决垃圾网站的跨域问题
        }
    })
        .then((response) => {
            return res.json({
                code: 200,
                data: response.data
            })
        })
        .catch((error) => {
            console.log(error)
            return res.json({
                code: 201,
                msg: "server error：获取歌曲信息失败"
            })
        })

})
// 获取视频url
router.post("/video", async (req, res) => {
    let {videoId} = req.body
    if (!videoId)
        return res.json({
            code: 201,
            msg: "缺少必要参数"
        })
    axios
        .post(`${webHost}/static/js/play.php`, {
            id: videoId,
            type: "video"
        }, {
            headers: {
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
                "Content-Type": "application/x-www-form-urlencoded",
                "Referer": `${webHost}/static/js/play.php` // 解决垃圾网站的跨域问题
            }
        })

        .then(response => {
            // console.log(response.data)
            let a = js_decrypt_video(response.data.list)
            return res.json({
                code: 200,
                data: a
            })
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: "server error:视频url error"
            })
        })
})
// 热门歌单：类别
router.get("/hotSong/type", async (req, res) => {
    axios
        .post(`${webHost}/playtype/index.html`)
        .then(response => {
            let $ = cheerio.load(response.data)
            let typeList = []
            $(`div.layui-container div.ilingku_fl`).each((index, item) => {
                let type = $(item).children('li:first').text().replace(":", "")
                let list = []
                $(item).children('li:first').nextAll().each((index2, item2) => {
                    let typeName = $(item2).text()
                    let typeId = $(item2).children("a").attr('href').split("/")[2].split(".")[0]
                    list.push({typeName, typeId})
                })
                typeList.push({type, list})
            })
            return res.json({
                code: 200,
                typeList
            })
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: 'server error:歌单类目 error'
            })
        })
})
// 热门歌单：歌单
router.post("/hotSong", async (req, res) => {
    let {typeId, pageNumber} = req.body
    if (!typeId) typeId = "index"
    if (!pageNumber) pageNumber = 1
    axios
        .post(`${webHost}/playtype/${typeId}/${pageNumber}.html`)
        .then((response) => {
            let $ = cheerio.load(response.data)
            if (!$('div').hasClass("video_list")) {
                return res.json({
                    code: 201,
                    msg: "数据不存在或已被删除"
                })
            }
            let list = []
            $(`div.video_list ul li`).each((index, item) => {
                let a = $(item).find("div.pic")
                let img = a.find("a img").attr("src").split("url=")[1]
                let count = a.children("span").text()

                let b = $(item).find("div.name a")
                let listId = b.attr("href").split("/")[2].split(".")[0]
                let title = b.text()

                list.push({
                    img, count, title, listId,
                })
            })
            let totalPage = 0, nowPageNumber = 0
            let ta_a_count = $("div.video_list div.page a").length;
            let nowTag_a = $("div.video_list div.page a.current")
            nowPageNumber = Number(nowTag_a.text())
            if (ta_a_count > 1) {
                let lastTag_a = $("div.video_list div.page a:last")
                if (lastTag_a.hasClass("current")) {
                    totalPage = Number(lastTag_a.text())
                } else {
                    totalPage = Number(lastTag_a.attr("href").split("/")[3].split(".")[0])
                }
            } else {
                totalPage = 1
            }
            return res.json({
                code: 200,
                list,
                totalPage,
                nowPageNumber
            })
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: "server error：获取热门歌单失败"
            })
        })
})
// 热门歌单：曲目
router.post("/hotSong/list", async (req, res) => {
    let {typeId, pageNumber} = req.body
    if (!typeId)
        return res.json({
            code: 201,
            msg: "缺少必要参数"
        })
    if (!pageNumber) pageNumber = 1
    axios.post(`${webHost}/playlist/${typeId}/${pageNumber}.html`)
        .then(response => {
            let $ = cheerio.load(response.data)
            if (!$('div').hasClass("lkmusic_list")) {
                return res.json({
                    code: 201,
                    msg: "数据不存在或已被删除"
                })
            }
            let list = []
            $(`div.lkmusic_list ul li`).each((index, item) => {
                let a = $(item).find("div.pic a")
                let img = a.children("img").attr("src")
                let time = a.children("span").text()

                let b = $(item).find("div.list_r div.name a.url")
                let title = b.text()
                let songId = b.attr("href").split("/")[2].split(".")[0]

                let c = $(item).find("div.list_r div.name a.mv")
                let hasVideo = false, videoId = null
                if (c.length > 0) {
                    hasVideo = true
                    videoId = c.attr("href").split("/")[2].split(".")[0]
                }

                let d = $(item).find("div.list_r p a.singer")
                let singer = d.text()
                let singerId = d.attr("href").split("/")[2].split(".")[0]

                list.push({
                    img, time, title, songId, singer, singerId, hasVideo, videoId
                })
            })
            let totalPage = 0, nowPageNumber = 0
            let tag_a_count = $("div.lkmusic_list div.page a").length
            let nowTag_a = $("div.lkmusic_list div.page a.current")
            nowPageNumber = Number(nowTag_a.text())
            if (tag_a_count > 1) {
                let lastTag_a = $("div.lkmusic_list div.page a:last")
                if (lastTag_a.hasClass("current")) {
                    totalPage = Number(lastTag_a.text())
                } else {
                    totalPage = Number(lastTag_a.attr("href").split("/")[3].split(".")[0])
                }
            } else {
                totalPage = 1
            }
            return res.json({
                code: 200,
                list,
                totalPage,
                nowPageNumber
            })
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: "server error：获取歌单详情失败"
            })
        })
})
// 热门歌单的曲目（接口摘去，实际曲目列表数量不一致。已有替代，暂停使用）
router.post("/hotSong/list2", async (req, res) => {
    let {songId} = req.body
    if (!songId)
        return res.json({
            code: 201,
            msg: "缺少必要参数"
        })
    axios
        .post(`${webHost}/plug/playlist.php`, {
            id: songId
        }, {
            headers: {
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
                "Content-Type": "application/x-www-form-urlencoded",
                "referer": `${webHost}/plug/playlist.php`
            }
        })
        .then(response => {
            host = response.request.host
            protocol = response.request.protocol
            let a = js_decrypt(response.data.list)
            a.forEach((item, index) => {
                // item.src = addressToComplete(item.src)
                item.cover = addressToComplete(item.cover)
                item.songTitle = item.title.split(" - ")[0]
                item.singer = item.title.split(" - ")[1]
                item.ac = item.src.split("ac=")[1].split("&id=")[0]
                item.id = item.src.split("id=")[1]
                delete item.src
            })
            return res.json({
                code: 200,
                data: a
            })
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: "server error：获取歌曲详情失败"
            })
        })
})
// 根据热门歌单的曲目数据，重定向歌曲地址（实际重定向经常出问题。已有替代，暂停使用）
router.post('/hotSong/url', async (req, res) => {
    let {ac, id, type} = req.body
    axios
        .post(`${webHost}/plug/down.php?ac=${ac}&id=${id}&type=${type}`, {}, {
            headers: {
                "Content-Type": "text/html",
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
                "Referer": `${webHost}/plug/down.php?ac=${ac}&id=${id}`,
            },
            maxRedirects: 0, // 禁用自动重定向
            validateStatus: (status) => status >= 200 && status < 400 // 允许 3xx 状态码
        })
        .then(response => {
            return res.json({
                code: 200,
                data: response.headers.location
            })
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: "server error：获取歌曲信息失败，请重试"
            })
        })
})
// 热门歌手
router.post("/hotSinger", async (req, res) => {
    let {pageNumber} = req.body
    if (!pageNumber) pageNumber = 1
    axios
        .post(`${webHost}/singerlist/index/index/index/index/${pageNumber}.html`)
        .then(response => {
            let $ = cheerio.load(response.data)
            if (!$('div').hasClass("singer_list")) {
                return res.json({
                    code: 201,
                    msg: "数据不存在或已被删除"
                })
            }
            let list = []
            $(`div.singer_list ul li`).each((index, item) => {
                let a = $(item).find("div.pic a")
                let img = a.children("img").attr("src").split("url=")[1]
                let b = $(item).find("div.name a")
                let singer = b.text()
                let singerId = b.attr("href").split("/")[2].split(".")[0]
                list.push({
                    img, singer, singerId
                })
            })
            let totalPage = 0, nowPageNumber = 0
            let lastTag_a = $("div.singer_list div.page a:last")
            let nowTag_a = $("div.singer_list div.page a.current")
            if (lastTag_a.hasClass("current")) {
                totalPage = Number(lastTag_a.text())
            } else {
                totalPage = Number(lastTag_a.attr("href").split("/")[6].split(".")[0])
            }
            nowPageNumber = Number(nowTag_a.text())
            return res.json({
                code: 200,
                list,
                totalPage,
                nowPageNumber
            })
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: "server error：获取热门歌手"
            })
        })
})
// 热门歌手的曲目
router.post("/hotSinger/song", async (req, res) => {
    let {singerId, pageNumber} = req.body
    if (!singerId)
        return res.json({
            code: 201,
            msg: "缺少必要参数"
        })
    if (!pageNumber) pageNumber = 1
    axios
        .post(`${webHost}/singer/${singerId}/${pageNumber}.html`)
        .then(response => {
            let $ = cheerio.load(response.data)
            if (!$('div').hasClass("lkmusic_list")) {
                return res.json({
                    code: 201,
                    msg: "数据不存在或已被删除"
                })
            }
            let list = []
            $('div.lkmusic_list ul li').each((index, item) => {
                let a = $(item).find("div.pic a")
                let img = a.children("img").attr("src")
                let time = a.children("span").text()

                let b = $(item).find("div.list_r div.name a.url")
                let title = b.text()
                let songId = b.attr("href").split("/")[2].split(".")[0]

                let c = $(item).find("div.list_r div.name a.mv")
                let hasVideo = false, videoId = null
                if (c.length > 0) {
                    hasVideo = true
                    videoId = c.attr("href").split("/")[2].split(".")[0]
                }

                let d = $(item).find("div.list_r p a")
                let singer = d.text()
                let singerId = d.attr("href").split("/")[2].split(".")[0]
                list.push({
                    img, time, title, songId, singer, singerId, hasVideo, videoId
                })
            })
            let totalPage = 0, nowPageNumber = 0
            let lastTag_a = $("div.lkmusic_list div.page a:last")
            let nowTag_a = $("div.lkmusic_list div.page a.current")
            if (lastTag_a.hasClass("current")) {
                totalPage = Number(lastTag_a.text())
            } else {
                totalPage = Number(lastTag_a[0].attribs["href"].split("/")[3].split(".")[0])
            }
            nowPageNumber = Number(nowTag_a.text())
            return res.json({
                code: 200,
                list,
                totalPage,
                nowPageNumber
            })
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: "server error：获取歌手歌单"
            })
        })
})
// 热搜词
router.get("/hotSearchWord", (req, res) => {
    axios
        .get(`https://kuwo.cn/openapi/v1/www/search/searchKey?key=&httpsStatus=1&plat=web_www&from=`)
        .then(response => {
            return res.json(response.data)
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: "server error:热搜词 error"
            })
        })
})
// 搜索
router.post("/search", async (req, res) => {
    let {word, pageNumber} = req.body
    if (!word)
        return res.json({
            code: 201,
            msg: "缺少必要参数"
        })
    word = word.replaceAll(" ", "+")
    if (!pageNumber) pageNumber = 1
    axios
        .post(`${webHost}/so/song/${word}/${pageNumber}.html`)
        .then(response => {
            // console.log(response.data)
            let $ = cheerio.load(response.data)
            if (!$('div').hasClass("lkmusic_list")) {
                return res.json({
                    code: 201,
                    msg: "数据不存在或已被删除"
                })
            }
            let list = []
            $('div.lkmusic_list ul li').each((index, item) => {
                let a = $(item).find("div.pic a")
                let img = a.children("img").attr("src")
                let time = a.children("span").text()

                let b = $(item).find("div.list_r div.name a.url")
                let title = b.text()
                let songId = b.attr("href").split("/")[2].split(".")[0]

                let c = $(item).find("div.list_r p a.singer")
                let singer = c.text()
                let singerId = c.attr("href").split("/")[2].split(".")[0]

                list.push({
                    img, time, title, songId, singer, singerId,
                })
            })
            let totalPage = 0, nowPageNumber = 0
            let lastTag_a = $("div.lkmusic_list div.page a:last")
            let nowTag_a = $("div.lkmusic_list div.page a.current")
            if (lastTag_a.hasClass("current")) {
                totalPage = Number(lastTag_a.text())
            } else {
                totalPage = Number(lastTag_a.attr("href").split("/")[4].split(".")[0])
            }
            nowPageNumber = Number(nowTag_a.text())
            return res.json({
                code: 200,
                list,
                totalPage,
                nowPageNumber
            })
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: "server error：搜索"
            })
        })
})
// 大家在听
router.get("/playLog", async (req, res) => {
    axios
        .post(`${webHost}/plug/playlog.php`, {}, {
            headers: {
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
                "Content-Type": "application/x-www-form-urlencoded",
                "Referer": `${webHost}/plug/playlog.php` // 解决垃圾网站的跨域问题
            }
        })
        .then(response => {
            host = response.request.host
            protocol = response.request.protocol
            let $ = cheerio.load(response.data)
            let playLog = []
            $(`body li`).each((index, item) => {
                let a = $(item).find("div.pic a")
                let img = a.children("img").attr('src')
                let time = a.children("span").text()

                let b = $(item).find("div.list_r div.name a.url")
                let title = b.text()
                let playLogType = b.attr("href").split("/")[1]
                let songId = null, videoId = null
                if (playLogType === "video") {
                    videoId = b.attr("href").split("/")[2].split(".")[0]
                }
                if (playLogType === "play") {
                    songId = b.attr("href").split("/")[2].split(".")[0]
                }
                let c = $(item).find("div.list_r p a.singer")
                let singer = c.text()
                let singerId = c.attr("href").split("/")[2].split(".")[0]

                playLog.push({
                    img, time, title, playLogType, songId, videoId, singer, singerId
                })
            })

            return res.json({
                code: 200,
                playLog,
            })
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: "server error:大家在听 error"
            })
        })
})
// 榜单类别
router.get("/bang", async (req, res) => {
    axios
        .post(`${webHost}/list/share.html`)
        .then(response => {
            let $ = cheerio.load(response.data)
            if (!$("div").hasClass("ilingku_fl")) {
                return res.json({
                    code: 201,
                    msg: "数据不存在或已被删除"
                })
            }
            let bangType = []
            $("div.ilingku_fl li a").each((index, item) => {
                let bangId = $(item).attr("href").split("/")[2].split(".")[0]
                let bang = $(item).text()
                let onBang = $(item).hasClass("current")
                bangType.push({bang, bangId, onBang})
            })
            return res.json({
                code: 200,
                bangType
            })
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: "server error:音乐榜单 error"
            })
        })
})
// 榜单类别的曲目
router.post("/bang/list", async (req, res) => {
    let {bangId, pageNumber} = req.body
    if (!bangId)
        return res.json({
            code: 201,
            msg: "缺少必要参数"
        })
    if (!pageNumber) pageNumber = 1
    axios
        .post(`${webHost}/list/${bangId}/${pageNumber}.html`)
        .then(response => {
            host = response.request.host
            protocol = response.request.protocol
            let $ = cheerio.load(response.data)
            if (!$('div').hasClass("lkmusic_list")) {
                return res.json({
                    code: 201,
                    msg: "数据不存在或已被删除"
                })
            }
            let list = [] // 新歌榜
            $(`div.lkmusic_list ul li`).each((index, item) => {
                let a = $(item).find("div.pic a")
                let img = addressToComplete(a.children("img").attr('src'))
                let time = a.children("span").text()

                let b = $(item).find("div.list_r div.name a.url")
                let title = b.text()
                let songId = b.attr("href").split("/")[2].split(".")[0]

                let c = $(item).find("div.name a.mv")
                let hasVideo = false
                let videoId = null
                if (c.length > 0) {
                    hasVideo = true
                    videoId = c.attr("href").split("/")[2].split(".")[0]
                }

                let d = $(item).find("div.list_r p a.singer")
                let singer = d.text()
                let singerId = d.attr("href").split("/")[2].split(".")[0]

                list.push({
                    img, time, title, songId, hasVideo, videoId, singer, singerId
                })
            })
            let totalPage = 0, nowPageNumber = 0
            let nowTag_a = $("div.lkmusic_list div.page a.current")
            let lastTag_a = $("div.lkmusic_list div.page a:last")
            if (lastTag_a.hasClass("current")) {
                totalPage = Number(lastTag_a.text())
            } else {
                totalPage = Number(lastTag_a.attr("href").split("/")[3].split(".")[0])
            }
            nowPageNumber = Number(nowTag_a.text())
            return res.json({
                code: 200,
                list,
                totalPage,
                nowPageNumber
            })
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: "server error:音乐榜单详情 error"
            })
        })
})
// 新碟专辑
router.get("/album", async (req, res) => {
    axios
        .post(`${webHost}/albumlist/index.html`)
        .then(response => {
            let $ = cheerio.load(response.data)
            if (!$('div').hasClass("video_list"))
                return res.json({
                    code: 201,
                    msg: "数据不存在或已删除"
                })
            let album = []
            $("div.video_list ul li").each((index, item) => {
                let a = $(item).find("div.pic")
                let img = a.find("a img").attr('src').split("url=")[1]
                let count = a.children("span").text()

                let b = $(item).find("div.name a")
                let albumName = b.text()
                let albumId = b.attr("href").split("/")[2].split(".")[0]
                album.push({
                    img, count, albumName, albumId
                })
            })
            return res.json({
                code: 200,
                album
            })
        })
        .catch(err => {
            console.log(err)
            return res.json({
                code: 201,
                msg: "server error:新碟专辑 error"
            })
        })
})
// 新碟专辑的曲目
router.post("/album/list", async (req, res) => {
    let {albumId, pageNumber} = req.body
    if (!albumId)
        return res.json({
            code: 201,
            msg: "缺少必要参数"
        })
    if (!pageNumber) pageNumber = 1
    axios
        .post(`${webHost}/album/${albumId}/${pageNumber}.html`)
        .then(response => {
            let $ = cheerio.load(response.data)
            if (!$('div').hasClass("lkmusic_list"))
                return res.json({
                    code: 201,
                    msg: "数据不存在或已删除"
                })
            let albumList = []
            $("div.lkmusic_list ul li").each((index, item) => {
                let a = $(item).find("div.pic a img")
                let img = a.attr("src").split("url=")[1]

                let b = $(item).find("div.list_r div.name a.url")
                let title = b.text()
                let songId = b.attr("href").split("/")[2].split(".")[0]

                let c = $(item).find("div.list_r p a.singer")
                let singer = c.text()
                let singerId = c.attr("href").split("/")[2].split(".")[0]
                albumList.push({img, title, songId, singer, singerId})
            })
            let totalPage = 0, nowPageNumber = 0
            let nowTag_a = $("div.lkmusic_list div.page a.current")
            let lastTag_a = $("div.lkmusic_list div.page a:last")
            if (lastTag_a.hasClass("current")) {
                totalPage = Number(lastTag_a.text())
            } else {
                totalPage = Number(lastTag_a.attr("href").split("/")[3].split(".")[0])
            }
            nowPageNumber = Number(nowTag_a.text())
            return res.json({
                code: 200,
                albumList,
                totalPage,
                nowPageNumber
            })
        })
        .catch(err => {
            return res.json({
                code: 201,
                msg: "server error:新碟专辑曲目 error"
            })
        })
})
router.get("/getTest", (req, res) => {
    return res.json({
        code: 200,
        data: "get请求成功"
    })
})
router.post("/postTest", (req, res) => {
    return res.json({
        code: 200,
        data: "post请求成功"
    })
})

/*地址补全*/
function addressToComplete(path, base) {
    if (!base)
        base = protocol + host
    return new URL(path, base).href
}

// 解析音乐url
function js_decrypt(str) {
    let key = "52c7f81cd24c9699";//16位加密key
    let iv = "42e07d2f7199c35d";//16位偏移量
//密钥16位
    key = CryptoJS.enc.Utf8.parse(key);
//加密向量16位
    iv = CryptoJS.enc.Utf8.parse(iv);
    let decrypted = CryptoJS.AES.decrypt(str, key, {
        iv: iv,
        padding: CryptoJS.pad.Pkcs7
    }).toString(CryptoJS.enc.Utf8);
    // console.log(decrypted)
    // 使用正则表达式匹配 song 数组的内容
    // 正则表达式匹配 song 数组内容（处理换行和空格）
    const songRegex = /song:\s*(\[[\s\S]*?])(?=,\s*autoPlay)/;
    const match = decrypted.match(songRegex);
    const songArrayStr = match ? match[1] : '';
    return eval(songArrayStr);
}

// 解析视频url
function js_decrypt_video(str) {
    let key = "52c7f81cd24c9699";//16位加密key
    let iv = "42e07d2f7199c35d";//16位偏移量
//密钥16位
    key = CryptoJS.enc.Utf8.parse(key);
//加密向量16位
    iv = CryptoJS.enc.Utf8.parse(iv);
    let decrypted = CryptoJS.AES.decrypt(str, key, {
        iv: iv,
        padding: CryptoJS.pad.Pkcs7
    }).toString(CryptoJS.enc.Utf8);
    // 使用正则表达式匹配 song 数组的内容
    // 正则表达式匹配 video {}内容（处理换行和空格）
    const songRegex = /video:\s*(\{[\s\S]*?})(?=,\s*contextmenu)/;
    const match = decrypted.match(songRegex);
    const songArrayStr = match ? match[1] : '';
    return eval('(' + songArrayStr + ')');
}

export default router